<cfcomponent output="false">
	
	<!--- --->

	<cffunction name="getLogs" access="public" output="true" returntype="query">
		<cfargument name="age" required="false" default="2" hint="in days" />
		<cfargument name="name" required="false" default="" />
		<cfargument name="message" required="false" default="" />
		<cfargument name="detail" required="false" default="true" />
		<cfargument name="limit" required="false" default="" />

		<cfset var local = {} />

		<cfquery name="local.getLogs" datasource="#$.site.getVar('datasource')#">
			select
			hex(craftivity_log.id) as id,
			now() as now,
			craftivity_log.name,
			hex(craftivity_log.user_id) as user_id,
			craftivity_log.message,
			<cfif arguments.detail>
				craftivity_log.session,
				craftivity_log.arguments,
				craftivity_log.error,
			<cfelse>
				'' as session,
				'' as arguments,
				'' as error,
			</cfif>
			craftivity_log.created,
			user.first_name,
			user.last_name,
			business.name as business_name
			from craftivity_log
			left join user on user.id = craftivity_log.user_id
			left join business on business.id = user.business_id
			where craftivity_log.active = 1
			<cfif arguments.name neq "">
				and craftivity_log.name = #$.database.string(arguments.name)#
			</cfif>
			<cfif arguments.age neq "">
				and craftivity_log.created > date_add(now(),interval -#arguments.age# hour)
			</cfif>
			<cfif arguments.message neq "">
				and soundEx(craftivity_log.message) = soundEx(#$.database.string(arguments.message)#)
			</cfif>
			order by created desc
			<cfif arguments.limit neq "">
				limit #arguments.limit#
			</cfif>
		</cfquery>
		
		<cfreturn local.getLogs />
		
	</cffunction>
	
	<!--- --->

</cfcomponent>